package game;

import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;
import java.util.LinkedList;

public class Audios
{
	static Audios instance;
	static LinkedList<AudioClip> clipList = new LinkedList<AudioClip>();
	
	static String[] stSounds = new String[]
	{
		"/sound/botao.wav", // 0 - botao
		"/sound/caixaRegistradora.wav", // 1 - caixa registradora
		"/sound/newTurno.wav", // 2 - novo turno
		"/sound/vitoria.wav", // 3 - vitoria
		"/sound/derrota.wav", // 4 - derrota
	};
	
		private Audios(){}
		
		static Audios getInstance()
		{
			if(instance==null)
				instance = new Audios();
			
			return instance;
		}
		public void loadSongs()
		{
			for(int i = 0; i< stSounds.length; i++)
			{
				clipList.add(Applet.newAudioClip(getURL(stSounds[i])));
			}
		}
		public void Play(int indexPlay)
		{
			
			clipList.get(indexPlay).play();
			
		}
		public void Loop(int indexPlay)
		{
			clipList.get(indexPlay).loop();
		}
		
		private URL getURL(String filename) {
	        URL url = null;
	        try {
	            url = this.getClass().getResource(filename);
	        }
	        catch (Exception e) { }
	        return url;
	   }
		public void stopAll()
		{
			for(int i = 0; i< stSounds.length; i++)
			{
				try{
				clipList.get(i).stop();
				}
				catch(Exception e)
				{
					
				}
			}
		}
	
}
	

